package com.linchong.concurrency.syncContainer;

import com.linchong.concurrency.annoations.UnThreadSafe;

import java.util.Vector;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2020-12-08 21:19
 * @Description: VectorExample2$同步容器的调用顺序
 */
@UnThreadSafe
public class VectorExample2 {

	private static Vector<Integer> vector = new Vector<>();

	public static void main(String[] args) {
		while (true) {
			for (int i = 0; i < 10; i++) {
				vector.add(i);
			}

			Thread thread1 = new Thread() {
				@Override
				public void run() {
					for (int i = 0; i < vector.size(); i++) {
						vector.remove(i);
					}
				}
			};

			Thread thread2 = new Thread() {
				@Override
				public void run() {
					for (int i = 0; i < vector.size(); i++) {
						vector.get(i);
					}
				}
			};

			thread1.start();
			thread2.start();
		}
	}
}
